Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 15, 2025

Description

This PR attempts to address Issue #7990 by adding proper support for the browser tool in GitHub Codespaces environments.

Problem

The browser tool was failing in GitHub Codespaces with the error:

error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory

This occurs because the Chromium binary downloaded by puppeteer-chromium-resolver lacks required system dependencies in containerized environments.

Solution

  1. Devcontainer Configuration: Added .devcontainer/devcontainer.json with all necessary Chromium dependencies that will be automatically installed when a Codespace is created or rebuilt.

  2. Runtime Detection: Added environment detection to identify when running in Codespaces and attempt to use system-installed Chromium first before falling back to downloading.

  3. Enhanced Error Messages: When the browser fails to launch in Codespaces, users now receive helpful instructions on how to fix the issue.

  4. Proper Sandbox Flags: Added appropriate browser launch flags for containerized/Linux environments to ensure compatibility.

Changes

  • Added .devcontainer/devcontainer.json with Chromium dependencies
  • Modified src/services/browser/BrowserSession.ts to detect Codespaces and use system Chromium
  • Modified src/services/browser/UrlContentFetcher.ts with the same enhancements
  • Updated tests to expect the new browser launch arguments

Testing

  • ✅ All existing tests pass
  • ✅ Linting passes
  • ✅ Type checking passes

Notes

The review identified an opportunity to extract the duplicated Codespaces detection logic into a shared utility, but this can be addressed in a follow-up PR if desired.

Fixes #7990


Important

Adds GitHub Codespaces support by handling Chromium dependencies and errors in BrowserSession.ts and UrlContentFetcher.ts.

  • Behavior:
    • Adds .devcontainer/devcontainer.json to install Chromium dependencies in Codespaces.
    • Detects Codespaces in BrowserSession.ts and UrlContentFetcher.ts to use system Chromium if available.
    • Provides error messages with instructions when browser launch fails in Codespaces.
    • Adds sandbox flags for Linux/Codespaces in BrowserSession.ts and UrlContentFetcher.ts.
  • Utilities:
    • Adds isCodespacesEnvironment(), fixCodespaceDependencies(), and isMissingDependencyError() in codespaceUtils.ts.
  • Testing:
    • Updates tests in UrlContentFetcher.spec.ts to expect new browser arguments.
    • Adds codespaceUtils.spec.ts to test new utility functions.

This description was created by Ellipsis for 9abfa0c. You can customize this summary. It will automatically update as commits are pushed.

@roomote roomote bot requested review from cte, jr and mrubens as code owners September 15, 2025 15:45
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Sep 15, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 15, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this code twice because copy-paste is my primary design pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These helper methods (isCodespacesEnvironment() and checkSystemChromium()) are duplicated in both BrowserSession.ts and UrlContentFetcher.ts. Could we extract them into a shared utility file like src/utils/browserEnvironment.ts to follow DRY principles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this duplication intentional? The --disable-gpu flag appears on line 113 and again on line 119. Same with --disable-dev-shm-usage on lines 110 and 119. Could we deduplicate these args?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message includes a hardcoded list of packages that might become outdated. Could we consider either:

  1. Referencing the devcontainer.json file
  2. Linking to documentation
  3. Creating a constant that's shared with the devcontainer configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a comment explaining why these environment variables are needed? It would help future maintainers understand that:

  • PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: Prevents downloading Chromium since we're using the system-installed version
  • PUPPETEER_EXECUTABLE_PATH: Points to the system Chromium installation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests verify the browser launch arguments but don't cover the new Codespaces-specific logic. Should we add tests for:

  • isCodespacesEnvironment() detection
  • checkSystemChromium() fallback behavior
  • The enhanced error messages in Codespaces?

- Add automatic detection of Codespaces environment
- Implement auto-fix using 'sudo apt --fix-broken install' when browser launch fails
- Add retry logic after fixing dependencies
- Create devcontainer configuration for seamless Codespaces setup
- Add comprehensive tests for new functionality

Fixes #7990
@roomote roomote bot force-pushed the fix/browser-tool-codespaces-7990 branch from 98ddcbb to 9abfa0c Compare September 15, 2025 16:15
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Sep 15, 2025
@roomote
Copy link
Contributor Author

roomote bot commented Sep 15, 2025

Updated implementation based on @LousyBook94's suggestion to use sudo apt --fix-broken install.

The new approach:

  • Automatically detects Codespaces environment
  • When browser launch fails due to missing dependencies, runs sudo apt --fix-broken install -y
  • Retries browser initialization after fixing dependencies
  • Includes comprehensive error detection for various missing library errors

This should provide a more robust solution that automatically fixes the issue without requiring manual intervention.

@daniel-lxs
Copy link
Member

#7990 (comment)

@daniel-lxs daniel-lxs closed this Sep 15, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 15, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 15, 2025
@daniel-lxs daniel-lxs deleted the fix/browser-tool-codespaces-7990 branch September 15, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] Browser tool does not run in a gh codespace environment

4 participants